home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Dynamic Re20794682001.psc / clsButton.cls < prev    next >
Encoding:
Visual Basic class definition  |  2001-03-21  |  2.9 KB  |  126 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsButton"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  16. Option Explicit
  17.  
  18. '
  19. ' The class handles skinnable buttons. The button position
  20. ' can be supplied in absolute or relative coordiantes (see later).
  21. '
  22.  
  23. Private mUpImage As New clsBitmap
  24. Private mDownImage As New clsBitmap
  25.  
  26. Private mWidth As Long
  27. Private mHeight As Long
  28.  
  29. Private mX As Long
  30. Private mY As Long
  31. Private mForm As Form
  32.  
  33. Public Property Get Height() As Long
  34.     Height = mHeight
  35. End Property
  36.  
  37. Public Property Get Width() As Long
  38.     Width = mWidth
  39. End Property
  40.  
  41. Public Property Get X() As Long
  42.     X = mX
  43. End Property
  44.  
  45. Public Property Get Y() As Long
  46.     Y = mY
  47. End Property
  48.  
  49. Public Property Get DownImageHDC() As Long
  50.     DownImageHDC = mDownImage.hDC
  51. End Property
  52.  
  53. Public Property Get UpImageHDC() As Long
  54.     UpImageHDC = mUpImage.hDC
  55. End Property
  56.  
  57. ' Initializes the button.
  58. '
  59. ' If the x/y parameter is negative, it means that the value is
  60. ' relative to the right side of the parent form.
  61. ' The Paint() methods compute the actual position of the buttons,
  62. ' each time the form is redrawn.
  63. '
  64. Public Sub Init(UpImageFileName As String, _
  65.                 DownImageFileName As String, _
  66.                 X As Long, Y As Long, _
  67.                 ParentForm As Form)
  68.     
  69.     mUpImage.LoadFile UpImageFileName
  70.     mDownImage.LoadFile DownImageFileName
  71.     
  72.     mWidth = mUpImage.Width
  73.     mHeight = mUpImage.Height
  74.     mX = X
  75.     mY = Y
  76.     
  77.     Set mForm = ParentForm
  78.     
  79. End Sub
  80.  
  81. ' Test whether the given (x,y) coordinate is inside the
  82. ' button area, and return TRUE is so.
  83. ' Used by the parent form in its MouseDown/MouseUp events to
  84. ' determine if a button was pressed/released.
  85. Public Function HitTest(X As Long, Y As Long) As Boolean
  86.  
  87.     If (X >= AbsX() And X < AbsX() + mWidth) And _
  88.        (Y >= AbsY() And Y < AbsY() + mHeight) Then
  89.         HitTest = True
  90.     End If
  91.  
  92. End Function
  93.  
  94. Public Sub PaintUpImage()
  95.     ' Note that the 'real' x/y values are used
  96.     mUpImage.Paint mForm.hDC, AbsX(), AbsY()
  97. End Sub
  98.  
  99. Public Sub PaintDownImage()
  100.     mDownImage.Paint mForm.hDC, AbsX(), AbsY()
  101. End Sub
  102.  
  103. ' Get the real X position of the button.
  104. ' If the X coordinate is negative, compute AbsX as the
  105. ' distance from the right side
  106. Public Property Get AbsX() As Long
  107.  
  108.     If mX >= 0 Then
  109.         AbsX = mX
  110.     Else
  111.         AbsX = mForm.ScaleWidth + mX
  112.     End If
  113.  
  114. End Property
  115.  
  116. Public Property Get AbsY() As Long
  117.  
  118.     If mY >= 0 Then
  119.         AbsY = mY
  120.     Else
  121.         AbsY = mForm.ScaleHeight + mY
  122.     End If
  123.  
  124. End Property
  125.  
  126.